#ifndef AUDIOCAPTURESERVICE_H
#define AUDIOCAPTURESERVICE_H

#include <QObject>
#include <QTimer>
#include <QDateTime>
#include "audiocapture.h"
#include "wasapi_loopback_capture_simple.h"
#include "config_manager.h"

class AudioCaptureService : public QObject
{
    Q_OBJECT

public:
    explicit AudioCaptureService(QObject *parent = nullptr);
    ~AudioCaptureService();

    void start();
    void stop();
    
    // 配置管理
    void showConfiguration() const;
    void reloadConfiguration();

private slots:
    void onCaptureStatusChanged(bool isCapturing);
    void onCaptureError(const QString &error);
    void onTransmissionStatusChanged(bool isTransmitting);
    void onTransmissionError(const QString &error);
    void onTransmissionDataSent(qint64 bytesSent);
    void onTransmissionConnectionEstablished();
    void onTransmissionConnectionLost();
    void attemptReconnect();
    void updateStatus();

private:
    void startTransmission();
    void startAudioCapture();

    // 音频捕获器
    AudioCapture *m_audioCapture;
    WasapiLoopbackCaptureSimple *m_wasapiCapture;
    
    // 配置管理器
    ConfigManager *m_configManager;
    
    // 定时器
    QTimer *m_reconnectTimer;
    QTimer *m_statusTimer;
    
    // 状态
    bool m_isConnected;
    qint64 m_totalBytesSent;
    qint64 m_packetsSent;
};

#endif // AUDIOCAPTURESERVICE_H